/**
 * @class ÐºÐ½Ð¾Ð¿ÐºÐ° - DIV
 * Ð•ÑÐ»Ð¸ Ð²Ñ‹Ð´ÐµÐ»ÐµÐ½Ð¸Ðµ ÑÑ…Ð»Ð¾Ð¿Ð½ÑƒÑ‚Ð¾ Ð¸ Ð½Ð°Ñ…Ð¾Ð´Ð¸Ñ‚ÑÑ Ð²Ð½ÑƒÑ‚Ñ€Ð¸ div'a - Ð¾Ð½ ÑƒÐ´Ð°Ð»ÑÐµÑ‚ÑÑ
 * ÐÐ¾Ð²Ñ‹Ðµ div'Ñ‹ ÑÐ¾Ð·Ð´Ð°ÑŽÑ‚ÑÑ Ñ‚Ð¾Ð»ÑŒÐºÐ¾ Ð¸Ð· Ð½ÐµÑÑ…Ð»Ð¾Ð¿Ð½ÑƒÑ‚Ð¾Ð³Ð¾ Ð²Ñ‹Ð´ÐµÐ»ÐµÐ½Ð¸Ñ
 *
 * @param  elRTE  rte   Ð¾Ð±ÑŠÐµÐºÑ‚-Ñ€ÐµÐ´Ð°ÐºÑ‚Ð¾Ñ€
 * @param  String name  Ð½Ð°Ð·Ð²Ð°Ð½Ð¸Ðµ ÐºÐ½Ð¾Ð¿ÐºÐ¸ 
 * 
 * @author:    Dmitry Levashov (dio) dio@std42.ru
 * @copyright: Studio 42, http://www.std42.ru
 **/
elRTE.prototype.ui.prototype.buttons.div = function(rte, name) {
	this.constructor.prototype.constructor.call(this, rte, name);
	
	this.command = function() {
		var n, nodes;
		if (this.rte.selection.collapsed() && (n = this.rte.dom.selfOrParent(this.rte.selection.getNode(), /^DIV$/))) {
			$(n).replaceWith($(n).html());
		} else {
			nodes = this.rte.selection.selected({wrap : 'all', tag : 'div'});
			nodes.length && this.rte.selection.select(nodes[0], nodes[nodes.length-1]);
		}
		this.rte.ui.update(true);
	}
	
	this.update = function() {
		if (this.rte.selection.collapsed()) {
			if (this.rte.dom.selfOrParent(this.rte.selection.getNode(), /^DIV$/)) {
				this.domElem.removeClass('disabled').addClass('active');
			} else {
				this.domElem.addClass('disabled').removeClass('active');
			}
		} else {
			this.domElem.removeClass('disabled').removeClass('active');
		}
	}
}

